package me.yricky.alia.ui

import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.*

/**
 * @author Yricky
 * @date 2022/2/6
 */

fun Modifier.pointerEvent(
    eventType: PointerEventType,
    pass: PointerEventPass = PointerEventPass.Main,
    onEvent: AwaitPointerEventScope.(event: PointerEvent) -> Unit
) = pointerInput(eventType, pass, onEvent) {
    awaitPointerEventScope {
        while (true) {
            val event = awaitPointerEvent(pass)
            if (event.type == eventType) {
                onEvent(event)
            }
        }
    }
}